package com.qf.common.utils;

import android.app.Activity;
import android.content.ContentResolver;
import android.provider.Settings;
import android.view.Window;
import android.view.WindowManager;

/**
 * Created by Administrator on 2018/6/15.
 */

public class ScreenBrightUtils {
    /**
     * 调整屏幕的亮度
     * @param level
     * @param activity
     */
    public void setBrightness(int level, Activity activity) {
        ContentResolver cr = activity.getContentResolver();
        Settings.System.putInt(cr, "screen_brightness", level);
        Window window = activity.getWindow();
        WindowManager.LayoutParams attributes = window.getAttributes();
        float flevel = level;
        attributes.screenBrightness = flevel / 255;
        activity.getWindow().setAttributes(attributes);
    }
}
